package org.fing.edu.uy.esbadp.requirements;

import java.util.logging.Level;

import org.fing.edu.uy.esbadp.core.compare.wsdl.WsdlDiff;
import org.fing.edu.uy.esbadp.core.constants.EsbAdpMonitoringPropertyKeys;
import org.fing.edu.uy.esbadp.core.entity.MetaDataConfig;
import org.fing.edu.uy.esbadp.core.entity.PropertiesMonitoring;
import org.fing.edu.uy.esbadp.core.interfaces.IAdpServiceRequirement;
import org.fing.edu.uy.esbadp.logger.LoggerADP;

public class AdpRequirmentRequiredMessageTransformation implements IAdpServiceRequirement {
	
	private static java.util.logging.Logger logger = LoggerADP.getLogger(AdpRequirmentRequiredMessageTransformation.class.getSimpleName());
	
	@Override
	public boolean needRequiredAdp(MetaDataConfig metadata,	PropertiesMonitoring properties) {
		//si las propiedad que define las diferencias del contrato contiene alguna
		//sera necesario adaptar para este requerimiento
		Object prop = properties.getPropertyValue(EsbAdpMonitoringPropertyKeys.contractChange);
		if (prop != null){			
			if(prop instanceof WsdlDiff){
				WsdlDiff diff = (WsdlDiff) prop;
				if(diff.getOperations().size()>0){
					return true;
				}else{
					return false;
				}
			}else{
				logger.log(Level.WARNING, "The property " + EsbAdpMonitoringPropertyKeys.contractChange + " must be instance of "  + WsdlDiff.class.getCanonicalName() + ".");
				return false;
			}						
		}else{
			logger.log(Level.WARNING, "The property " + EsbAdpMonitoringPropertyKeys.contractChange + " is not present.");
			return false;
		}
	}
	
}
